<script setup lang="ts">
import { getFileList, getFile } from "@/api/search";

const props: any = defineProps({
  comProps: {
    type: Object,
  },
});

const previewData = ref();
const emit = defineEmits(["close"]);
const handleClose = () => {
  emit("close");
};
const get_file = async (path: any) => {
  if (!path) return;
  try {
    let res: any = await getFile({
      filePath: path,
    });
    return new Blob([res], { type: "text/plain" }).text();
  } catch (err) {
    return "";
  }
};
// console.log("props", props.preview);
watch(
  props.comProps,
  (val) => {
    // console.log("val", val);
    if (val?.filePath) {
      get_file(val.filePath).then((res) => {
        previewData.value = res;
        // console.log("previewData.value", previewData.value);
      });
    }
  },
  { immediate: true }
);
</script>

<template>
  <PreviewContianer :handleClose="handleClose">
    <template v-slot="{ clientHeight }">
      <el-scrollbar :style="{ height: clientHeight }">
        <div class="text" v-html="previewData"></div>
      </el-scrollbar>
    </template>
  </PreviewContianer>
</template>

<style lang="scss" scoped></style>
